#导入pyecharts库中的options模块
from pyecharts import options as opts
#导入pyecharts库中charts模块的WordCloud类
from pyecharts.charts import WordCloud
import jieba           #导入jieba库
#以只读模式打开文件并读取文件内容
with open('某电商平台某款连衣裙的商品评价.txt','r') as file:
    text=file.read()
words=jieba.lcut(text)
word_counts={}
for word in words:
    if len(word) > 1:
        #词语出现频率累加
        word_counts[word]=word_counts.get(word,0)+1
#创建WordCloud类对象，并设置初始配置项中的网页标题
wordCloud=WordCloud(init_opts=opts.InitOpts(page_title='词云图'))
#添加数据，并设置词语字体大小范围和词云图轮廓("diamond"表示钻石型)
wordCloud.add(series_name='',data_pair=word_counts.items(),
              word_size_range=[20,60],shape='diamond')
wordCloud.set_global_opts(
    title_opts=opts.TitleOpts(
        title='某电商平台某款连衣裙商品评价词云图',
        pos_left='center'),
    legend_opts=opts.LegendOpts(is_show=False)
)
wordCloud.render('例8-1.html')